﻿@{Layout = null;}
@model Monitor.Models.Json.ClassifDealerModel
<h2>Информация о дилерской организации</h2>
@Html.HiddenFor(model=>model.Id)
@Html.HiddenFor(model => model.FullName)
@if (Model != null)
{
    <div id="info" style="padding: 20px">
        <div>
            <b>
                @Html.DisplayFor(model => model.FullName)
            </b>
        </div>
        <div>
            @Html.Label(Model.FullName)
        </div>
        <div>
            <b>
                @Html.LabelFor(model => model.Contract) 
            </b>
        </div>
        <div class="view">
            @Html.Label(Model.Contract,new {id="ViewContract"})
        </div>
        <div class="edit">
            @Html.TextAreaFor(model => model.Contract)
        </div>
    </div>
}
else
{
   <p class="view">Информация отсутствует</p> 
    <div class="edit" style="padding: 20px">
        <div>
            <b>
                @Html.LabelFor(model => model.Contract) 
            </b>
        </div>
        <div>
            @Html.TextAreaFor(model => model.Contract)
        </div>
    </div>
}
<div class="buttonGroup">
    <div class="view button" onclick="Edit()">Редактировать</div>
    <div class="view button" onclick="Clear()">Очистить</div>
</div>
<div class="buttonGroup">
    <div class="edit button" onclick="Submit()">Сохранить</div>
    <div class="edit button" onclick="Cansel()">Отмена</div>  
</div>


<script src="~/Scripts/jqx-all/jqxbuttongroup.js"></script>

<script>
    function Edit() {
        $('.view').hide();
        $('.edit').show();
    }

    function Submit() {
        var PageModel = new Object();
        PageModel.Id = $('#Id').val();
        PageModel.FullName = $('#FullName').val();
        PageModel.Contract = $('#Contract').val();
        $.ajax({
            url: '/data/ServiseInfo',
            type: 'POST',
            data: PageModel,
            success: function (data) {
                $('.view').show();
                $('.edit').hide();
                $('#ViewContract').text(PageModel.Contract);
            },
            error: function () {
                alert('Невозможно подключиться к серверу данных.');
            }
        });
    }
    function Cansel() {
        $('.view').show();
        $('.edit').hide();
    }
    function Clear() {
        var PageModel = new Object();
        PageModel.Id = $('#Id').val();
        $('info').hide();
    }
    
    $(document).ready(function () {
        $(".button").jqxButton({ width: '100', height: '18' });
        $(".buttonGroup").jqxButtonGroup({ mode: 'default' });
        $('.edit').hide();
    });
</script>
